package com.example.myspringboot.service.impl;

import com.example.myspringboot.service.TestServer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

import java.util.concurrent.CompletableFuture;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * @author zheng
 */
@Service
public class TestServerImpl implements TestServer {

    public final String STATIC_INFO = "123";

    @Autowired
    private RedisTemplate<String, String> redisTemplate;

    @Override
    public String testFutter() {
        CompletableFuture<String> str = CompletableFuture.supplyAsync(() ->{
            return null;
        });
        return null;
    }

    @Override
    public void testString() {
        redisTemplate.opsForValue().set("test", "test");
        //取值
        String testValue = (String)redisTemplate.opsForValue().get("test");
        System.out.println(testValue);

//        redisTemplate.opsForValue().set("test", "test", 100, TimeUnit.MILLISECONDS);
        //key不存在存值，存在返回false，多用于分布式锁
        Boolean aBoolean = redisTemplate.opsForValue().setIfAbsent("city1234", "nanjing");
        System.out.println(aBoolean);
    }


}
